package com.woniuxy.service.impl;

import com.woniuxy.entity.DoctorAdvice;
import com.woniuxy.entity.Nurse;
import com.woniuxy.mapper.DoctorAdviceMapper;
import com.woniuxy.mapper.NurseMapper;
import com.woniuxy.service.DoctorAdviceService;
import com.woniuxy.service.SaasService;
import com.woniuxy.util.GetUserContent;
import com.woniuxy.util.ResponseData;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DoctorAdviceServiceImpl implements DoctorAdviceService, SaasService {
    @Autowired
    DoctorAdviceMapper doctorAdviceMapper;
    @Autowired
    NurseMapper nurseMapper;
    @Override
    public ResponseData<?> queryByDoCaseId(Integer patId) {
        List<DoctorAdvice> doctorAdvices = doctorAdviceMapper.queryByDoCaseId(patId);
        return new ResponseData<>().ok(doctorAdvices);
    }

    @Override
    @SneakyThrows
    public ResponseData<?> updateNurId(Integer id) {
        Long userId = (Long) GetUserContent.getUserInfo().get("userId");
        Nurse nurse = nurseMapper.queryNurse(Math.toIntExact(userId));
        doctorAdviceMapper.updateNurId(nurse.getId(),id);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> addDocAd(DoctorAdvice doctorAdvice) {
        doctorAdviceMapper.addDocAd(doctorAdvice);
        return new ResponseData<>().ok();
    }
}
